#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
char* newenv = (char*)"MYVAL=487666749";
char*const addenv[] = 
{
    (char* const)"MYVAL=487666749",
    (char* const)"MYVAL1=666666666",
    (char* const)"MYVAL2=111111111",
    NULL
};


int main()
{
    printf("我是一个进程，我要开始执行了！\n");
    //execl("/usr/bin/top","top",NULL);
    //printf("我执行结束了！:%d\n",ret);
    
    pid_t id = fork();
    if(id == 0)
    {
        //子进程
        printf("我是子进程,pid:%d\n",getpid());
        char*const argv[]=
        {
            (char*const)"proc_c++",
            (char*const)"-a",
            (char*const)"-b",
            NULL
        };
        int i = 0;
        for(;addenv[i];i++)
        {
            putenv(addenv[i]);
        }

        extern char** environ;
        //execvp("./proc_c++",argv);
        execvpe("./proc_c++",argv,environ);
        //execl("./proc_c++","proc_c++",NULL);
        //execl("/usr/bin/python3","python","proc.py",NULL);
        //execl("/usr/bin/bash","bash","proc.sh",NULL);
        exit(1);
        
    }

    //父进程
    waitpid(id,NULL,0);   
    
    printf("父进程执行完毕！\n");

    return 0;
}
